﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Automobile.service.BLL;
using Automobile.service.Model;
using System.Web.SessionState;

namespace Automobile.service.UI.Hander
{
    /// <summary>
    /// LoginHandler 的摘要说明
    /// </summary>
    public class LoginHandler : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string empname = context.Request.Form["empname"];
            string emppwd = context.Request.Form["emppwd"];
            string yzm = context.Request.Form["yzm"];
            if (yzm.ToLower() == context.Session["CheckCode"].ToString().ToLower())
            {
                EmployeeBLL bll = new EmployeeBLL();
                string landing = bll.Landing(empname, emppwd);
                context.Response.Write(landing);
                if (landing == "登录成功")
                {
                    context.Session["empname"] = context.Request.Form["empname"];
                    context.Session["empid"] = bll.GetEmpidByLanding(empname, emppwd);
                    JournalBLL jbll = new JournalBLL();
                    jbll.AddJourna_Landing(Convert.ToInt32(context.Session["empid"]));
                }
            }
            else
            {
                context.Response.Write("验证码错误");
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}